//import * as wasm from "rust-wasm-fetch-canvas";
import {AB} from "wasmdemo";



//wasm.unred("assets/images/image.png", "wasmCanvas");

// async function run() 
// { 
//   //await init(); // Initialize module 
//   wasm.unred("assets/images/image.png", "wasmCanvas");
// } 
// run(); 
var WIDTH = 640;
var HEIGHT = 320

const ab = AB.new("wasmCanvas", WIDTH, HEIGHT);

//ab.set_axis(-10, 10, -1000, 1000);
//ab.draw_polynomial([-1, 1, 0,0, 0,1]);

//ab.draw_png("assets/images/image.png");

//ab.draw_julia_set(WIDTH, HEIGHT, -0.15, 0.65)
ab.init_decoder("avc1.4D0014", WIDTH, HEIGHT)
ab.get_stream("wss://localhost:8000/stream?uid=112233")
//ab.render_video("assets/bunny.h264/bunny.h264_0011.h264")
{
  //茱莉亚集
  const realInput = document.getElementById('real');
  const imaginaryInput = document.getElementById('imaginary');
  const juliaBtn = document.getElementById('btn_julia');

  juliaBtn.addEventListener('click', () => {
      const real = parseFloat(realInput.value) || 0;
      const imaginary = parseFloat(imaginaryInput.value) || 0;
      ab.draw_julia_set(500, 500, real, imaginary);
  });

  //多项式
  const polyInput = document.getElementById('polynomial');
  const axisInput = document.getElementById('axis');
  const polyBtn = document.getElementById('btn_poly');  
  polyBtn.addEventListener('click', () => {
    
      function toNumber(value) {
        return Number(value);
      }

      const poly = polyInput.value.split(',').map(toNumber);
      const axis = axisInput.value.split(',').map(toNumber); 
      
      //ab.set_axis(-10, 10, -1000, 1000);
      //ab.draw_polynomial_with_scale(poly, axis[0], axis[1],axis[2],axis[3]);
      //ab.set_axis(-10, 10, -1000, 1000);
      //ab.draw_polynomial([-1, 1, 0,0, 0,1]);
      ab.draw_polynomial_with_scale(poly, axis[0], axis[1],axis[2],axis[3]);
  });

  //ab.draw_julia_set( WIDTH, HEIGHT, realInput.value, imaginaryInput.value);
}